package Thread;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
// 返回线程执行的结果，并且可以处理异常
class MyCallable implements Callable<String> {
    @Override
    public String call() throws Exception {
        return "Callable Result";
    }
}

public class demo3Callable {
    public static void main(String[] args) {
        Callable<String> callable = new MyCallable();
        FutureTask<String> futureTask = new FutureTask<>(callable);
        Thread thread = new Thread(futureTask);
        thread.start();

        try {
            // Get the result from the task
            String result = futureTask.get();
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


